// 不显示类型转换产生的溢出警告。
#![allow(overflowing_literals)]

pub fn example() {
    let decimal = 65.4321_f32;
    //无法采用隐式类型转换
    //let integer:u8 = decimal;

    let integer = decimal as u8;
    let character = integer as char;
    println!("Casting: {}->{}->{}",decimal,integer,character);
    // 当把任何类型转换为无符号类型 T 时，会不断加上或减去 (std::T::MAX + 1)
    // 直到值位于新类型 T 的范围内。
    println!("256 as a i8 is {}",256 as i8);
    //0011/1110/1000只保留对应的字节范围内的有效
    println!("1000 as a u16 is: {}", 1000 as u8);

    // 128 转成 u8 还是 128，但转到 i8 相当于给 128 取八位的二进制补码，其值是：
    println!(" 128 as a i8 is : {}", 128 as i8);
    // -1 + 256 = 255
    println!("  -1 as a u8 is : {}", (-1i8) as u8);
}